﻿using System;
using System.Collections.Generic;
using System.Web;

namespace TraditionalMalteseCuisine.App_Code.Functions
{
    public class Validation_Functions
    {
        //*************************************************
        //                   Methods
        //*************************************************
        #region Methods
        public static bool IsNumeric(char keyPressed)
        {
            bool is_numeric = true;

            switch (keyPressed)
            {
                case '-':
                case '0':
                case '1':
                case '2':
                case '3':
                case '4':
                case '5':
                case '6':
                case '7':
                case '8':
                case '9':
                    is_numeric = false;
                    break;
                case ' ':
                    is_numeric = false;
                    break;
            }

            return is_numeric;
        }

        public static bool IsDecimal(char keyPressed)
        {
            bool is_numeric = true;

            switch (keyPressed)
            {
                case '-':
                case '.':
                case '0':
                case '1':
                case '2':
                case '3':
                case '4':
                case '5':
                case '6':
                case '7':
                case '8':
                case '9':
                    is_numeric = false;
                    break;
                case ' ':
                    is_numeric = false;
                    break;
            }

            return is_numeric;
        }

        public static bool IsNumeric(string value)
        {
            try
            {
                int.Parse(value);

                return true;
            }
            catch { return false; }
        }

        public static bool IsDecimal(string value)
        {
            try
            {
                double.Parse(value);

                return true;
            }
            catch { return false; }
        }

        public static bool IsDateTime(string value)
        {
            try
            {
                DateTime.Parse(value);

                return true;
            }
            catch { return false; }
        }

        public static bool IsBoolean(string value)
        {
            try
            {
                bool.Parse(value);

                return true;
            }
            catch { return false; }
        }

        public static bool IsValidImageFile(string imageLocation)
        {
            bool isImage = false;

            switch (imageLocation.Substring(imageLocation.LastIndexOf('.')).ToLower())
            {
                case ".bmp":
                case ".gif":
                case ".jpeg":
                case ".jpg":
                case ".tif":
                case ".png":
                    isImage = true;
                    break;
            }

            return isImage;
        }
        #endregion
        //*************************************************
    }
}